# CC=gcc-linaro-5.3-2016.02-x86_64_armeb-linux-gnueabihf/bin/armeb-linux-gnueabihf-gcc
CC=gcc
CFLAGS=-std=c99 -I ./src -g 
LDFLAGS=-static 

SM_BIN=libsm.a
SM_SRCS=$(wildcard src/*.c)
SM_OBJS=$(SM_SRCS:.c=.o)
SM_DEPENDS=$(SM_SRCS:.c=.d)

SM_TEST_BIN=test_sm
SM_TEST_SRCS=$(wildcard test/*.c)
SM_TEST_OBJS=$(SM_TEST_SRCS:.c=.o)
SM_TEST_DEPENDS=$(SM_TEST_SRCS:.c=.d)

.PHONY: all doc clean

all: $(SM_BIN) $(SM_TEST_BIN) doc

doc:
	doxygen doc/doxyfile

$(SM_BIN): $(SM_OBJS)
	$(AR) -rcs $@ $^

$(SM_TEST_BIN): $(SM_TEST_OBJS) $(SM_BIN)
	$(CC) -o $@ $^ $(LDFLAGS) 

sinclude $(SM_DEPENDS) $(SM_TEST_DEPENDS)

test/%.d: test/%.c
	@echo "create depend"
	$(CC) -MM $(CFLAGS) $< > $@.$$$$; \
	sed 's,\($*\)\.o[ :]*,test/\1.o $@: ,g' < $@.$$$$ > $@; \
	$(RM) $@.$$$$

src/%.d: src/%.c
	@echo "create depend"
	$(CC) -MM $(CFLAGS) $< > $@.$$$$; \
	sed 's,\($*\)\.o[ :]*,src/\1.o $@: ,g' < $@.$$$$ > $@; \
	$(RM) $@.$$$$




clean:
	rm $(SM_DEPENDS) $(SM_OBJS) $(SM_BIN) $(SM_TEST_DEPENDS) $(SM_TEST_OBJS) $(SM_TEST_BIN) 
	rm -r html
	rm -r latex
